#include <iostream>
#include <vector>

using namespace std;

vector<int> path;
int n, m;
bool st[20];
int cnt = 0;

void dfs()
{
	if(path.size() == m)
	{
		for(auto x : path) cout << x << " ";
		cout << endl;
		cnt++;
		return;
	}
	for(int i = 1; i <= n; i++)
	{
		if(!st[i])
		{
			st[i] = true;
			path.push_back(i);
			dfs();
			path.pop_back();
			st[i] = false;
		}
	}
}

int main()
{
	cin >> n >> m;
	
	dfs();
	cout << cnt << endl;
	return 0;
}
